/**
 * 包含应用中所有的接口的请求函数
 * 每个函数返回的值都为promise
 *  可以根据接口文档定义接口的请求
 */

import ajax from "./ajax";


const BASE="";

//老式写法
// export function reqLogin(useranme,password){
//     return ajax("/login",{useranme,password},'POST')
// }
//登录接口
export const reqLogin=(username,password)=>ajax(BASE+"/login",{username,password},'POST');

//获取一级分类/二级分类的接口
export const reqCategorys=(parentId)=>ajax(BASE+'/manage/category/list',{parentId})

//添加分类
export const reqAddCategory=(categoryName,parentId)=>ajax(BASE+"/manage/category/add",{categoryName,parentId},'POST')

//更新分类
export const reqUpdateCategory=({categoryName,categoryId})=>ajax(BASE+"/manage/category/update",{categoryName,categoryId},'POST')

//删除分类   //即使不传参数也要放一个空的对象在那里
export const reqDeleteCategory=(categoryId)=>ajax(BASE+`/manage/category/delete/${categoryId}`,{},'DELETE')

//根据分类id获取分类
export const reqCategory=(categoryId)=>ajax(BASE+'/manage/category/info',{categoryId})

//查询商品分页列表
export const reqProducts=(pageNum,pageSize)=>ajax(BASE+"/manage/product/list",{pageNum,pageSize})

//搜索商品分页列表(根据商品名称和商品描述)
/**
 * 
 * searchType:搜索的类型,productName/productDesc
 */
export const reqSearchProducts=({pageNum,pageSize,searchName,searchType})=>ajax(BASE+"/manage/product/search",{
    pageNum,
    pageSize,
    [searchType]:searchName
})

//更新商品的上架和下架的状态
export const reqUpdateStatus=(productId,status)=>ajax(BASE+'/manage/product/updateStatus',{productId,status},'POST')

//删除图片
export const reqDeleteImg=(name)=>ajax(BASE+'/manage/img/delete',{name},'POST')

// //添加商品
// export const reqAddProduct=(product)=>ajax(BASE+"/manage/product/add",product,'POST')

// //修改商品
// export const reqUpdateProduct=(product)=>ajax(BASE+"/manage/product/update",product,'POST')

//更新或者修改
export const reqAddOrUpdateProduct=(product)=>ajax(BASE+"/manage/product/"+(product._id?'update':'add'),product,'POST');

//获取角色列表
export const reqRoles=()=>ajax(BASE+"/manage/role/list");

//添加角色
export const reqAddRole=(roleName)=>ajax(BASE+"/manage/role/add",{roleName},'POST');

//更新角色权限
export const reqUpdateRole=(role)=>ajax(BASE+"/manage/role/update",role,'POST');

//更新列表的角色的信息
export const reqUpdateListRole=(role)=>ajax(BASE+"/manage/role/list/update",role,'POST');

//删除角色的信息
export const reqRoleDelete=(id)=>ajax(BASE+"/manage/role/delete",{id},'POST');

//获取所有用户
export const reqUsers=()=>ajax(BASE+"/manage/user/list")    

//添加或更新用户
export const reqAddOrUpdateUser=(user)=>ajax('/manage/user/'+(user._id?'update':'add'),user,'POST');

//删除指定的用户
export const reqDeleteUser=(userId)=>ajax(BASE+"/manage/user/delete",{userId},'POST');
